<?php

    if (!defined("EXPONENT")) exit("");
    $subject = null;		
    if (isset($_POST['id'])) {
        $subject = $db->selectObject('subjects', 'id='.intval($_POST['id']));
        /*if ($album != null) {
        $loc = unserialize($album->location_data);
        }*/ 
    } else {
        /*
        // No rank in this section
        $album->rank = $db->max('album', 'rank', null, "location_data='".serialize($loc)."'");
        if ($album->rank == null) {
        $album->rank = 0;
        } else { 
        $album->rank += 1;
        }*/
    }

    //if (exponent_permissions_check("manage",$loc)) {	
    if (exponent_users_isAdmin() && exponent_users_isLoggedIn()) {
        //$config = $db->selectObject('albummodule_config',"location_data='".serialize($loc)."'");
        //  if (!$config) {
        //do nothing here yes.
        //	   $config->album_type=0; // 0 for christian
        //}

        $subject= prayonline_subject::subject_update($_POST, $subject);
        //$subject->location_data = serialize($loc);
        //$album->album_type = $config->album_type;
        if (isset($subject->id)) {
            // calculate all song length
            $db->updateObject($subject,"subjects");
        } else {
            $subject->id = $db->insertObject($subject,"subjects");
        }		
        //
        // okies, now we save the relative
        $pastors=$_POST['pastors'];
        // delete old
        $db->delete("pastor_subject","subject_id = {$subject->id}"); 
        $temp=null;
        $temp->subject_id = $subject->id;
        if ($pastors != null)
        {
            foreach ($pastors as $key=>$value)
            {
                $temp->pastor_id = $value;
                $db->insertObject($temp,"pastor_subject");
            }
        }
        exponent_flow_redirect(SYS_FLOW_ACTION);
        //redirect_to($url);
    } else {
        echo SITE_403_HTML;
    }


?>
